define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'litestore_e_user/index' + location.search,
                    add_url: 'litestore_e_user/add',
                    edit_url: 'litestore_e_user/edit',
                    del_url: 'litestore_e_user/del',
                    multi_url: 'litestore_e_user/multi',
                    table: 'litestore_e_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle:false,  
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'group_id', title: __('名录角色'),searchList: {"1":__('默认组'),"2":__('原料供应商'),"3":__('机制炭生产企业'),"4":__('机制炭批发商'),"5":__('设备供应商'),"6":__('果木炭生产企业'),"8":__('其他')},formatter: Table.api.formatter.status},
                        {field: 'companyname', title: __('Companyname'),operate:'LIKE %...%'},
                        {field: 'nickname', title: __('Nickname'),operate:'LIKE %...%'},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'avatar', title: __('Avatar'),operate:false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'region_city', title: __('Region_city'),operate:'LIKE %...%'},
                        {field: 'businesslicense_images', title: __('营业执照'),operate:false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'address', title: __('Address'),operate:false},
                        {field: 'work', title: __('Work'),operate:false},
                        {field: 'experience', title: __('Experience'),operate:false,formatter:function(value,row,index){value = !value?'':value; var lg =value.length;if(lg && lg>10){ return value.substring(0,10)+'....';}else{ return value;}}},
                        
                        {field: 'businessscope', title: __('Businessscope'),operate:false,formatter:function(value,row,index){value = !value?'':value; var lg =value.length;if(lg && lg>10){ return value.substring(0,10)+'....';}else{ return value;}}},
                        {field: 'companyprofile', title: __('Companyprofile'),operate:false,formatter:function(value,row,index){value = !value?'':value; var lg =value.length;if(lg && lg>10){ return value.substring(0,10)+'....';}else{ return value;}}},
                      //  {field: 'appr_status', title: __('Appr_status')},
                      {field: 'score', title: __('排名序号'),operate:false},
                        {field: 'level', title: __('会员级别'),searchList: {"1":__('免费会员'),"2":__('普通认证会员'),"3":__('明星认证会员')},formatter: Table.api.formatter.status},
                        //{field: 'level', title: __('名录角色'),searchList: {"1":__('默认组'),"2":__('原料供应商'),"3":__('机制炭生产企业')},formatter: Table.api.formatter.status},
                        {field: 'certify_status', title: __('Certify_status'), searchList: {"1":__('Certify_status 1'),"2":__('Certify_status 2'),"3":__('Certify_status 3')}, formatter: Table.api.formatter.status},
                        {field: 'appr_status', title: __('Appr_status'), searchList: {"1":__('未提交审核'),"2":__('个人审核中'),"3":__('企业认证审核中'),"4":__('个人审核通过'),"5":__('企业审核通过'),"6":__('个人认证审核失败'),"7":__('企业认证审核失败')}, formatter: Table.api.formatter.status},
                        //{field: 'appr_fail_reson', title: __('Appr_fail_reson'),operate:false},
                        {field: 'operate', title: __('Operate'), buttons:[
                            {
                                name: 'ok', text: '通过', title: '通过', icon: '', confirm: '确定通过审核吗？',
                                classname: 'btn btn-xs btn-success btn-ajax', 
                                url:'litestore_e_user/appr',
                                visible:function(row)
                                {
                                  if(Number(row['appr_status'])===2||Number(row['appr_status'])===3)
                                    {
                                        return   true;
                                    }
                                    else{
                                        return false;
                                   }
                                },
                                success:function(data, ret){
                                    $(".btn-refresh").trigger("click");
                                },
                                 error:function(err){
                                   console.log(err);
                                }
                            },
                            {
                                name: 'ject', text: '不通过', title: '不通过', icon: '', confirm: '确定通过拒绝审核吗？',
                                classname: 'btn btn-xs btn-success btn-ajax', 
                                url:'litestore_e_user/reject',
                                visible:function(row)
                                {
                                  if(Number(row['appr_status'])===2||Number(row['appr_status'])===3)
                                    {
                                        return   true;
                                    }
                                    else{
                                        return false;
                                   }
                                },
                                success:function(data, ret){
                                    $(".btn-refresh").trigger("click");
                                },
                                 error:function(err){
                                   console.log(err);
                                }
                            }

                        ],table: table, events: Table.api.events.operate, 
                        formatter: Table.api.formatter.operate,
                        formatter: function (value, row, index) { //隐藏自定义的视频按钮
                            var that = $.extend({}, this);
                            var table = $(that.table).clone(true);
                            
                            
                            
                     
                            
                            if(Number(row['appr_status'])===2){
                           //         $(table).data("operate-ok", null);  //隐藏按钮操作 video为自定义按钮的name 
                            }
                            that.table = table;
                            return Table.api.formatter.operate.call(that, value, row, index);
                            }
                        
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});